package com.github.number;

import org.junit.jupiter.api.Test;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author zhangcheng
 * @date 2023/8/30 10:16
 * @description
 */
public class TestFloat {

    public static void main(String[] args) {
        float f1 = 1234567.21F;
        Double d1 = 1234567890123.21D;
        System.out.println(f1);
        System.out.println(d1);
    }

    @Test
    public void test() {
        float f1 = 6171.21F;
        float f2 = 6151.11F;
        System.out.println(f1);
        System.out.println(f1 - f2);

        BigDecimal add = BigDecimal.valueOf(f1).subtract(BigDecimal.valueOf(f2));
        System.out.println(add.toPlainString());

        BigDecimal add2 = new BigDecimal(f1).subtract(new BigDecimal(f2));
        System.out.println(add2.toPlainString());

        BigDecimal add3 = new BigDecimal(Float.toString((f1))).subtract(new BigDecimal(Float.toString((f2))));
        add3 = add3.setScale(3, RoundingMode.HALF_UP);
        System.out.println(add3.toPlainString());
        System.out.println(add3.floatValue());
    }

    @Test
    public void test2() {
        Double f1 = 3276171.23D;
        Double f2 = 3276151.11D;
        System.out.println(f1 - f2);

        BigDecimal add = BigDecimal.valueOf(f1).subtract(BigDecimal.valueOf(f2));
        System.out.println(add.toPlainString());

        BigDecimal add2 = new BigDecimal(f1).subtract(new BigDecimal(f2));
        System.out.println(add2.toPlainString());

        BigDecimal add3 = new BigDecimal(Double.toString((f1))).subtract(new BigDecimal(Double.toString((f2))));
//        add3.setScale(1, RoundingMode.HALF_UP);
        System.out.println(add3.toPlainString());
        System.out.println(add3.floatValue());
        System.out.println(add3);


        Float f = 6416055.129f;
        System.out.println(f);
    }
}
